﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BookReader
{
    class gtCommand:ICommand
    {
        void ICommand.Execute(string[] param)
        {
            if (String.IsNullOrEmpty(StaticData.openBookString))
            {
                Console.WriteLine("没有打开的文件");
            }
            if(param.Length!=1){
                Console.WriteLine("参数错误："+((ICommand)this).Help());
            }

            int id = 0;
            if (!int.TryParse(param[0], out id))
            {
                Console.WriteLine("参数不是数字" + ((ICommand)this).Help());
                return;
            }
            id--;
            if (id > (StaticData.PageCount-1) || id < 0)
            {
                Console.WriteLine("没有这一页");
                return;
            }

            StaticData.PageIndex = id;
            int start = StaticData.PageIndex * StaticData.pageSize;
            for (int i = start, lc = 0; lc < StaticData.pageSize; i++, lc++)
            {
                if (i < StaticData.lines.Count)
                {
                    Console.WriteLine(StaticData.lines[i]);
                    StaticData.currentIndex = i;
                }
            }
            Console.WriteLine("(p" + (StaticData.PageIndex + 1) + ")");
        }

        string ICommand.Help()
        {
            return "gt命令：转跳到地N页 gt 页数 ";
        }
    }
}
